package com.viviet.coreservices.ewallet;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import com.viviet.mobileservices.util.Logit;

/**
 * <p>
 * Title:
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * 
 * <p>
 * Company:
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */
public class EWalletWSCaller {
	
	private final String TXNID = "123456";
	private final String USER = "vvmap";
	private final String PASSWORD = "vvmap";
	private final String CHANNEL = "MAP";
	private final Logit LOG = Logit.getInstance(EWalletWSCaller.class);
	
	public EWalletWSCaller() {

	}

	private String callWebService(String txnId, String user, String password,
			String txnDateTime, String chanel, String sender, String messageIn)
			throws Exception {
		EBankServiceSoap11BindingStub binding;
		try {
			binding = (EBankServiceSoap11BindingStub) new EBankServiceLocator().getEBankServiceHttpSoap11Endpoint();
		} catch (javax.xml.rpc.ServiceException jre) {
			jre.printStackTrace();
			throw jre;
		}

		// Time out after 10 minutes
		binding.setTimeout(600000);

		// Test operation
		return binding.processMessage(txnId, user, password, txnDateTime,
				chanel, sender, messageIn);
	}

	public String callService(String sender, String messageXML)
			throws Exception {
		DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");
		// return callWebService("123456", "vnpsms", "vnpsms",
		// dateFormat.format(new Date()) , "SMS", sender, messageXML);
		
		LOG.debug("### Message Input");
		LOG.debug("### Sender: "+sender);
		LOG.debug("### XML: "+messageXML);
		return callWebService("123456", USER, PASSWORD,
				dateFormat.format(new Date()), CHANNEL, sender, messageXML);
	}

	public String callServiceSMS(String sender, String messageXML)
			throws Exception {
		DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");
		return callWebService("123456", "vnpsms", "vnpsms",
				dateFormat.format(new Date()), "SMS", sender, messageXML);
		// return callWebService("123456", "vvib", "VVIBELDF93JK5O",
		// dateFormat.format(new Date()), "IB", sender, messageXML);
	}
	/*
	 * public static void main(String args[]) { String result = null;
	 * 
	 * String inputXML = "<input>" + "	<service>VPW</service> " +
	 * "	<verify_password> " + "		<login_id>0909638428</login_id> " +
	 * "		<login_pass>12345678</login_pass> " + "	</verify_password> " +
	 * "</input>";
	 * 
	 * EWalletWSCaller caller = new EWalletWSCaller(); // result =
	 * caller.callService("0983589789", "vv gd"); try { result =
	 * caller.callService("IBSYS", inputXML); } catch (Exception ex) {
	 * ex.printStackTrace(); }
	 * 
	 * System.out.println("Message out: " + result.substring(3,9)); } /*
	 */
}
